{% extends "base.html" %}

{% block title %}{{ course.title }} - {{ super() }}{% endblock %}

{% block content %}
<div class="container">
    <nav aria-label="breadcrumb" class="mt-3">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('learning.index') }}">在线学习</a></li>
            <li class="breadcrumb-item active">{{ course.title }}</li>
        </ol>
    </nav>

    <div class="card">
        <div class="card-body">
            <h1 class="card-title">{{ course.title }}</h1>
            
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div class="text-muted">
                    <span><i class="fas fa-user"></i> {{ course.user.username }}</span>
                    <span class="ms-3"><i class="fas fa-clock"></i> {{ course.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
                </div>
                <div>
                    <span class="me-3"><i class="fas fa-eye"></i> {{ course.views }}</span>
                </div>
            </div>

            <div class="card mb-4">
                <div class="card-body bg-light">
                    <h5 class="card-title">课程简介</h5>
                    <p class="card-text">{{ course.description }}</p>
                </div>
            </div>

            <div class="card-text mb-4">
                {{ course.content|safe }}
            </div>

            {% if current_user.is_authenticated and current_user.role == 'admin' %}
            <div class="btn-group">
                <a href="{{ url_for('learning.edit', id=course.id) }}" class="btn btn-outline-primary">编辑</a>
                <button type="button" class="btn btn-outline-danger" onclick="deleteCourse()">删除</button>
            </div>
            {% endif %}
        </div>
    </div>
</div>

{% if current_user.is_authenticated and current_user.role == 'admin' %}
<form id="delete-form" action="{{ url_for('learning.delete', id=course.id) }}" method="post" style="display: none;">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
</form>

<script>
function deleteCourse() {
    if (confirm('确定要删除这个课程吗？此操作不可恢复。')) {
        document.getElementById('delete-form').submit();
    }
}
</script>
{% endif %}
{% endblock %} 